/************************* 版权声明 *********************************
 * 
 * 版权所有：Apache License 2.0
 * 
 ************************* 版本声明 *********************************
 *@since jdk1.5
 *@version 0.1
 ************************* 变更记录 *********************************
 *
 * 创建者：bijiqiang Email:bijiqiang@gmail.com   创建日期： 2010-01-10
 * 创建记录：创建类结构。
 * 
 * 修改者：       修改日期：
 * 修改记录：
 *
 * 修改者：       修改日期：
 * 修改记录：
 * ……
 ************************* To  Do *********************************
 *
 * 1、实现所有未实现的方法（抛出UnsupportedOperationException的方法）。
 * 
 ************************* 随   笔 *********************************
 *
 * 
 * 
 ******************************************************************
 */
package com.realgodo.site.web.space;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.application.show.Show;
import com.realgodo.site.entity.relation.FriendConfig;
import com.realgodo.site.entity.relation.Relation;
import com.realgodo.site.entity.space.SpaceCover;
import com.realgodo.site.entity.space.SpaceNotice;
import com.realgodo.site.service.UserManager;
import com.realgodo.site.service.application.ShowManager;
import com.realgodo.site.service.relation.FriendConfigManager;
import com.realgodo.site.service.space.SpaceCoverManager;
import com.realgodo.site.service.space.SpaceNoticeManager;
import com.realgodo.site.service.space.SpacePointManager;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/") })
public class IndexController extends SpaceDefaultController {

	private static final long serialVersionUID = 1225210859568443074L;

	@Autowired
	private SpaceCoverManager spaceCoverManager;

	@Autowired
	private UserManager userManager;
	@Autowired
	private ShowManager showManager;
	@Autowired
	private FriendConfigManager friendCinfigManager;
	@Autowired
	private SpaceNoticeManager spaceNoticeManager;

	@Autowired
	private SpacePointManager spacePointManager;

	private List<FriendConfig> friendConfigList;

	private Page<SpaceNotice> noticePage = new Page<SpaceNotice>(5);

	private List<Show> show;

	private Long showCount;
	private Long spaceCoverCount;
	private Long moodCount;

	private Long spacePoint;

	public String execute() throws Exception {
		createSpaceVisit();
		if (super.getVSpace() == null) {
			return "toindex";
		}
		noticePage = this.spaceNoticeManager.findSpaceNotices(noticePage, super
				.getVSpace().getId());
		this.userManager.visitCount(super.getVSpace().getId());
		show = this.showManager.findShows(super.getVSpace().getId(), 8)
				.getResult();
		showCount = this.showManager.getShowCount(super.getVSpace().getId());
		moodCount = this.moodManager.getMoodCount(super.getVSpace().getId());
		spaceCoverCount = this.spaceCoverManager.getShowCoverCount(super
				.getVSpace().getId());
		spacePoint = this.spacePointManager.getSpacePointBySpace(
				super.getVSpace().getId()).getPoint();
		return SUCCESS;
	}

	/** 展示首页顶级朋友 */
	private String top() {
		super.getParamMap()
				.put("spaceId", super.getVSpace().getId().toString());
		super.getParamMap()
				.put("status", String.valueOf(Relation.STATUS_AGREE));
		super.getParamMap().put("isTop", String.valueOf(FriendConfig.IS));
		friendConfigList = friendCinfigManager.find(super.getParamMap());
		return SUCCESS;
	}

	/************* getter and setter **********/
	public List<SpaceCover> getSpaceCovers() {
		return (super.getVSpace() != null) ? this.spaceCoverManager
				.getSpaceCovers(super.getVSpace().getId(), 6) : null;
	}

	public Show getMyTopShow() {
		return (super.getVSpace() != null) ? this.showManager
				.getMyTopShow(super.getVSpace().getId()) : null;
	}

	public List<FriendConfig> getFriendConfigList() {
		if (friendConfigList == null && super.getVSpace() != null) {
			top();
		}
		return friendConfigList;
	}

	public List<Show> getShow() {
		return show;
	}

	public void setShow(List<Show> show) {
		this.show = show;
	}

	public Page<SpaceNotice> getNoticePage() {
		return noticePage;
	}

	public void setNoticePage(Page<SpaceNotice> noticePage) {
		this.noticePage = noticePage;
	}

	public Long getSpaceCoverCount() {
		return spaceCoverCount;
	}

	public Long getMoodCount() {
		return moodCount;
	}

	public Long getShowCount() {
		return showCount;
	}

	public Long getSpacePoint() {
		return spacePoint;
	}
}
